package br.ufc.great.client;

import java.io.Serializable;
import java.util.Vector;

import br.ufc.great.xml.XMLElement;

public class DTXTransaction implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3277750097032899516L;
	private String id;
	private int status;
	private Vector<DTXOperation> operations;
	
	public static final int NONE = 0;
	public static final int COMMITED = 1;
	public static final int ABORTED = 2;
	
	public DTXTransaction(String id) {
		this.id = id;
		operations = new Vector<DTXOperation>();
		status = NONE;
	}
	
	public String getId() {
		return id;
	}
	
	public void addQueryOperation(Vector<DTXSite> sites, String query) {
		operations.add(new DTXQueryOperation(String.valueOf(operations.size() + 1), sites, query));
	}
	
	public void addInsertOperation(Vector<DTXSite> sites, String query, int type, XMLElement constructor) {
		operations.add(new DTXInsertOperation(String.valueOf(operations.size() + 1), sites, query, type, constructor));
	}
	
	public Vector<DTXOperation> getOperations() {
		return operations;
	}
	
	public String getResults() {
		String results = "";
		for (int i = 0; i < operations.size(); i++) {
			DTXOperation operation = operations.elementAt(i);
			results += operation.getResult();
		}
		return results;
	}
	
	public int getStatus() {
		return status;
	}
	
	public void setStatus(int status) {
		this.status = status;
	}
	
}
